package bean;

import java.util.LinkedList;

import bean.Vertex;

public class Graph {
	private Vertex[] vertex;
	private int size;

	public int size() {
		return size;
	}
	public Graph(){
		
	}
	public Graph(int size) {
		this.vertex = new Vertex[size + 1];
		this.size = size;
		for (int i = 1; i <= size; i++)
			vertex[i] = new Vertex(i);
	}
	
	public void connect(  ){
		
	}

	public void connect(int node1, int node2, float distance) {
		this.vertex[node1].getLink().addNode(node2, distance);
		//this.vertex[node2].getLink().addNode(node1, distance);
	}

	public LinkedList<Integer> getChainByIndex(int index) {
		LinkedList<Integer> result = new LinkedList<Integer>();
		this.vertex[index].getLink().reset();
		Node temp=null;
		while ((temp=(this.vertex[index].getLink().next())) != null) {
			result.add(temp.index());
		}
		return result;
	}

	public float getDistence(int n1, int n2) {
		float dis = -1f;
		Node temp=null;
		while ((temp=(this.vertex[n1].getLink().next())) != null) {
			
			if (temp.index() == n2) {
				dis = temp.getDis();
				break;
			}
		}
		return dis;
	}
}
